#include "../game_server.cpp"
#include "../user.cpp"
#include "../room.cpp"
#include "../protocol_dist.hpp"
#include "ws_websocket.hpp"
#include <iostream>

using namespace std;
using namespace winux;
FASTDO_API void ActionMain(ProtocolC2STotalMsg *msg, pWsReqCtx ctx, GameServer &game)
{
    auto user = game.getUser(ctx);
    auto room = game.getRoomByUser(user);
    if (room)
    {
        if (room->totalDataTime <= msg->time)
        {
            room->totalDataTime = msg->time;
            room->totalData = msg->data;
        }

        ProtocolS2CTotalMsg rtn;
        rtn.time = msg->time;
        rtn.data = msg->data;
        if (msg->echo)
        {
            room->dispatch(&rtn);
        }
        else
        {
            room->dispatch(&rtn, user);
        }
    }
}